# -*- coding:utf-8 -*-
import os
import random
import sys
import threading

import requests
import datetime
from Crypto.Cipher import AES
import re
import json
import sqlite3

from multiprocessing import Lock
from binascii import b2a_hex, a2b_hex

import os


import time



task_queue = []

threads_list = []
lock = Lock()


def call():
    while True:
        task = None
        try:
            if len(task_queue) == 0:
                break
            lock.acquire()  # 上锁
            task = task_queue.pop()  # 争夺task
            lock.release()  # 解锁
            print("process:" + str(task))
            time.sleep(0.2)
        except:
            print("download err: "+task)




def get_link_from_db_download():
    for row in range(0, 100):
        task_queue.append(row)

    for i in range(0, 5):
        t = threading.Thread(target=call)
        t.setDaemon(True) #守护线程，让主线程等待子线程结束
        t.start()
        threads_list.append(t)


    for t in threads_list:
        t.join()


if __name__ == '__main__':
    get_link_from_db_download()